
import { BUTTONID ,URL} from '../../constance';
import backBtnClick from './backBtnClick';
import addBtnClick from './addBtnClick';
import commitBtnClick from './commitBtnClick';
import unCommitBtnClick from './unCommitBtnClick';
import editBtnClick from './editBtnClick';
import refreshBtnClick from './refreshBtnClick';
import deleteBtnClick from './deleteBtnClick';
import cancelBtnClick from './cancelBtnClick';
import copyBtnClick from './copyBtnClick';
import saveBtnClick from './saveBtnClick';
import addLineBtnClick from './addLineBtnClick';
import deleteLineBtnClick from './deleteLineBtnClick';
import copyLineBtnClick from './copyLineBtnClick';
import pasteLineBtnClick from './pasteLineBtnClick';
import cancelBBtnClick from './cancelBBtnClick';
import insertLineBtnClick from './insertLineBtnClick';
import { ajax,toast,promptBox } from 'nc-lightapp-front';

import bodyAfterEdit from '../afterEvents/bodyAfterEvent';
import ftDetailBtnClick from './ftDetailBtnClick';
import { STATUS } from '../../../../common/constant';
// 表头按钮区操作
function buttonClick(props, id) {
        switch (id) {
                case BUTTONID.Add:
                        addBtnClick.call(this, props);
                        break;
                case BUTTONID.Commit:
                        commitBtnClick.call(this, props);
                        break;
                case BUTTONID.UnCommit:
                        unCommitBtnClick.call(this, props);
                        break;
                case BUTTONID.Edit:
                        editBtnClick.call(this, props);
                        break;
                case BUTTONID.Delete:
                        deleteBtnClick.call(this, props);
                        break;
                case BUTTONID.Copy:
                        copyBtnClick.call(this, props);
                        break;
                case BUTTONID.Refresh:
                        refreshBtnClick.call(this, props);
                        break;
                case BUTTONID.Save:
                        saveBtnClick.call(this, props);
                        break;
                case BUTTONID.Cancel:
                        cancelBtnClick.call(this, props);
                        break;
                case BUTTONID.Back:
                        backBtnClick.call(this, props);
                        break; 
                case BUTTONID.ftDetail:
                        ftDetailBtnClick.call(this, props);
                        break;
                case "RedHandle":
                        createVoucher(props,"redHandle");
                        break;
                case "Voucher":
                        createVoucher(props,"Voucher")
                        break
        }
}



function createVoucher(props,action) { 
        let pk = props.form.getFormItemsValue("card_head", "pk_amortization") && props.form.getFormItemsValue("card_head", "pk_amortization").value;
        let data = [{
                ts: props.form.getFormItemsValue("card_head" ,"ts").value,
                pk:pk,
                action:action
        }]
        ajax({
                url: URL.Voucher,
                data: data,
                success: (res) => {
                        
                        refreshBtnClick.call(this, props);
                        toast({ content: '操作成功', color: STATUS.success });
    
                }
        })
    }

// 表体按钮操作
function lineBtnClick(moduleId, props, id, text, record, index) {
        switch (id) {
                        case BUTTONID.cardBody_1_AddLine:
                case BUTTONID.cardBody_2_AddLine:
                        addLineBtnClick.call(this, props, moduleId);
                        break;

                case BUTTONID.cardBody_1_DeleteLine:
                case BUTTONID.cardBody_2_DeleteLine:
                        deleteLineBtnClick.call(this, props, moduleId, record, index);
                        bodyAfterEdit.call(this,props,moduleId,'money');
                        break;
                case BUTTONID.cardBody_1_CopyLine:
                case BUTTONID.cardBody_2_CopyLine:
                        copyLineBtnClick.call(this, props, moduleId);
                        break;

                case BUTTONID.cardBody_1_PasteLineToTail:
                case BUTTONID.cardBody_1_PasteLine:
                case BUTTONID.cardBody_2_PasteLineToTail:
                case BUTTONID.cardBody_2_PasteLine:
                        pasteLineBtnClick.call(this, props, moduleId, record, index);
                        bodyAfterEdit.call(this,props,moduleId,'money');
                        break;

                case BUTTONID.cardBody_1_CancelB:
                case BUTTONID.cardBody_2_CancelB:
                        cancelBBtnClick.call(this, props, moduleId);
                        break;

                case BUTTONID.cardBody_1_InsertLine:
                case BUTTONID.cardBody_2_InsertLine:
                        insertLineBtnClick.call(this, props, moduleId, record, index);
                        break;
        }
}

export { buttonClick, lineBtnClick };
